module.exports = {
    insert(collection,insertData) {
        collection.insertMany(insertData,(err) => {
            if(err) throw err;
            console.log('insert success');
        })
    },
    delete(collection,whereData,deleteNum) {
        const deleteType = deleteNum === 1 ? 'deleteMany' : 'deleteOne';
        collection[deleteType](whereData,(err) => {
            if(err) throw err;
            console.log('delete sucecess');
        })
    },
    update(collection,whereData,updateData,updateNum) {
        const updateType = updateNum === 1 ? 'updateMany' : 'updateOne';
        collection[updateType](whereData,updateData,(err) => {
            if(err) throw err;
            console.log('update sucecess');      
        })
    },
    find(collection,whereData,showData) {
        collection.find(whereData,showData,(err,data) => {
            if(err) throw err;
            console.log(data);  
        })
    },
    paging(collection,whereData,showData,limitnum,count) {
        collection.find(whereData,showData).limit(limitnum).skip((count-1)*limitnum).exec((err,data) => {
            if(err) throw err;
            console.log(data);  
        })
    },
    sort(collection,whereData,showData,sortData) {
        collection.find(whereData,showData).sort(sortData).exec((err,data) => {
            if(err) throw err;
            console.log(data);  
        })
    },
    distinct(collection,key){
        collection.distinct(key, (err, data) => {
            if(err) throw err;
            console.log(data);  
        })
    }
}